// pages/home/components/objectDetails/objectDetails.js
var api = require('../../../../app/app.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    FloorDetails: {},
    IMG_URL: 'https://www.sdhjfu.com/smallhouse/public/admin/',
    indicator_dots: true,
    indicator_color: 'rgba(255, 255, 255, .7)',
    active_color: '#fff',
    indicatorDots: true,
    autoplay: true,
    interval: 3500,
    duration: 800,
    address_img: 'https://www.sdhjfu.com/smallhouse/public/tianxing/images/icon_address.jpg',
    telImg: 'https://www.sdhjfu.com/smallhouse/public/tianxing/images/details_tel.jpg',
    left: 0,
    phone:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '楼盘详情'
    })
    var that = this
    wx.request({
      url: api.FloorDetails,
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          FloorDetails: res.data
        })
      }
    })
  },
  // 一键导航
  addressClick: function() {
    var long = 117.751491
    var lati = 36.843223
    wx.openLocation({
      latitude: lati,
      longitude: long,
      name: '天兴·理想之城',
      address: '邹平市鹤伴五路与醴泉五路交汇处南200米路东项目现场营销中心'
    })
  },
  // 一键导航
  addressClick1: function () {
    var long = 117.737206
    var lati = 36.864433
    wx.openLocation({
      latitude: lati,
      longitude: long,
      name: '天兴·理想之城',
      address: '邹平市山南圣豪超市停车场东临鹤伴一路营销中心'
    })
  },
  // 拨打电话
  telClick: function() {
    wx.makePhoneCall({
      phoneNumber: this.data.FloorDetails.houre[0].house_iphone,
    })
  },
  // 拨打电话
  telClick1: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.FloorDetails.houre[0].house_iphoneone,
    })
  },
  //图片预览
  scrollImg: function(e){
    var ind = e.currentTarget.id
    var imgCurrent = this.data.IMG_URL + this.data.FloorDetails.apartmentre[ind].apartbigimage
    // console.log(imgCurrent)
    var result = []
    var apartment = this.data.FloorDetails.apartmentre
    for (let i in apartment) {
      result[i] = this.data.IMG_URL + apartment[i].apartbigimage
    }
    wx.previewImage({
      current: imgCurrent, // 当前显示图片的http链接
      urls: result // 需要预览的图片http链接列表
    })
  },
  // 跳转表单页面
  clickForm: function(){ // 跳转配置tabbar页面
    if (!this.data.phone) {
      wx.redirectTo({
        url: '/pages/authorization/authorization'
      })
    } else {
      wx.switchTab({
        url: '/pages/recommend/recommend/recommend',
      })
    } 
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取本地缓存
    var that = this
    wx.getStorage({
      key: 'userReInfo',
      success(res) {
        // console.log(res.data)
        var phone = res.data.phone
        that.setData({
          phone: phone
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})